﻿@model Wheeler.Web.ViewModels.UserViewModel
@using Wheeler.Web.Utility;

@{
	String pageTitle = "Edit User";
    if (Model != null && Model.ID == 0)
    {             
        pageTitle = "Add New User";
    }
    ViewBag.Title = Html.GetPageTitle(pageTitle);
	ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = AdminMenu.ManageUser;
	bool _HasSaved = ViewData.HasSaved();
}

<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>Enter necessary information and then click the Save button.</div>
</div>
<div class="jb-page-content">
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

	if (Model == null)
    {
        @: @Html.WarningMessageBox("Sorry! Requested User was not found for edit.")
    }
	else
	{
		if (_HasSaved) {
            @Html.SuccessMessageBox("Congratulations! The User saved successfully")
        }
        else if (ViewData[AppConstants.ViewDataKeys.SAVED] != null && !_HasSaved)
        {
            @Html.WarningMessageBox("Sorry! we could not save the User.")
        }
		@Html.HiddenFor(model => model.ID)

		<div class="editor-label">
			@Html.LabelFor(model => model.UserName)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.UserName)
			@Html.ValidationMessageFor(model => model.UserName)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.Password)
		</div>
		<div class="editor-field">
			@Html.PasswordFor(model => model.Password)
			@Html.ValidationMessageFor(model => model.Password)
		</div>
        <div class="editor-label">
			@Html.LabelFor(model => model.ConfirmPassword)
		</div>
		<div class="editor-field">
			@Html.PasswordFor(model => model.ConfirmPassword)
			@Html.ValidationMessageFor(model => model.ConfirmPassword)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.IsActive)
		</div>
		<div class="editor-field jb-inline-label">
			@Html.RadioButtonFor(model => model.IsActive, "true", new { id = "rdnIsActive_1" }) <label for="rdnIsActive_1">Yes</label>
            @Html.RadioButtonFor(model => model.IsActive, "false", new { id = "rdnIsActive_0" }) <label for="rdnIsActive_0">No</label>
			@Html.ValidationMessageFor(model => model.IsActive)
		</div>
		<div class="editor-label">
			@Html.LabelFor(model => model.GroupID)
		</div>
		<div class="editor-field">
			@Html.DropDownListFor(model => model.GroupID, BindSelectList.Groups())
			@Html.ValidationMessageFor(model => model.GroupID)
		</div>
		@*<div class="editor-label">
			@Html.LabelFor(model => model.LastLoggedIn)
		</div>
		<div class="editor-field">
			@Html.TextBoxFor(model => model.LastLoggedIn)
			@Html.ValidationMessageFor(model => model.LastLoggedIn)
		</div>*@
		<div class="jb-button-container">
			<button class="btn btn-primary" type="submit" data-loading-text="Saving...">Save</button> 
			@Html.AdminLink("Back to User List", "List", "User", new { @class = "btn" })
		</div>		
    }
}
</div>
@section JavaScriptPlaceHolder
{
@Html.JavaScript("jquery.validate.min.js", Url)
@Html.JavaScript("jquery.validate.unobtrusive.min.js", Url)
}

